package IO;

import java.io.File;

public class SystemInfo {
	
	public static String getApplicationDirectory()
	{
		String appDirectory = "";
		String userHome = System.getProperty("user.home");
		String sonnyDir = "Sonny";
		String separator = System.getProperty("file.separator");
		
		if(isMacOS())
		{
			appDirectory = userHome + separator + "Library" + separator + "Application Support" + separator + sonnyDir + separator;
		}
		else if (isWindowsOS())
		{
			appDirectory = userHome + separator + "Application Data" + separator + sonnyDir + separator;
		}
		else if (isLinuxOS())
		{
			appDirectory = userHome + separator + "." + sonnyDir + separator; //this looks effed, but I seen it done somewhere...
		}
		else
		{
			//omgwtfbbq
			//<Thumbs up> Quinn likes this;
			System.exit(1337);
		}
		
		// if the appDirectory doesn't exist then make it!
	    File appDir = new File(appDirectory);
	    if (!appDir.exists()) 
	    {
	      appDir.mkdirs();
	    }
		
		
		//System.out.println(appDirectory);
		return appDirectory;
	}
	
	/**
	 * Gets the directory path where torrents are downloaded
	 * @return the path where torrents are downloaded
	 * TODO: Let this be user-specifiable
	 */
	public static String getTorrentDirectory()
	{
		String userHome = System.getProperty("user.home");
		String separator = System.getProperty("file.separator");
		String torrentDir = userHome + separator + "Sonny_Torrents" + separator; 
		
		File tdir = new File(torrentDir);
		if (!tdir.exists())
		{
			tdir.mkdirs();
		}
		return torrentDir;
	}
	
	
	public static boolean isMacOS() 
	{
		String os = System.getProperty("os.name").toLowerCase();
		
		if (os.startsWith("mac"))
		{
			return true;
		}
		
		return false;
	}
	
	public static boolean isWindowsOS() 
	{
		String os = System.getProperty("os.name").toLowerCase();
		
		if (os.startsWith("windows"))
		{
			return true;
		}
		
		return false;
	}
	
	public static boolean isLinuxOS()
	{
		String os = System.getProperty("os.name").toLowerCase();
		if (os.startsWith("linux"))
		{
			return true;
		}
		return false;
	}
}
